<?php

class EntrepotController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function showAction()
    {
        $entrepot = new Application_Model_Dao_EntrepotMapper();
        $this->view->entries = $entrepot->fetchAll();
    }

    public function addAction() {
    	// action body
        $request = $this->getRequest();
        $form = new Application_Form_Entrepot();
        if($this->getRequest()->isPost())
        {
        	if ($form->isValid($request->getPost())) {
        		$entrepot = new Application_Model_BusiInfo_Entrepot($form->getValues());
        		$mapper  = new Application_Model_Dao_EntrepotMapper();
        		$mapper->save($entrepot);
        		return $this->_helper->redirector('show');
        	}
        }
        $this->view->form = $form;
    	
    }
    
    public function editAction() {
     	// action body
        $request = $this->getRequest();
        $entrepotId = $this->getRequest()->getParam('entrepotId');
        $mapper  = new Application_Model_Dao_EntrepotMapper();
        $entrepot = $mapper->find($entrepotId);
        $form = new Application_Form_Entrepot();
        $form->populate(array('id' 	=> $entrepot->get_id(),
        						'address' => $entrepot->get_address(),
        						'phone' => $entrepot->get_phone(),
        ));
       
        if($this->getRequest()->isPost())
        {
        	if ($form->isValid($request->getPost())) {
        		$entrepot = new Application_Model_BusiInfo_Entrepot($form->getValues());
        		$mapper->save($entrepot);
        		return $this->_helper->redirector('show');
        	}
        }
        $this->view->form = $form;
    	
    }
    
    
    public function deleteAction() {
    	$entrepotId = $this->getRequest()->getParam('entrepotId');
    	$mapper = new Application_Model_Dao_EntrepotMapper();
    	$mapper->delete($entrepotId);
    	return $this->_helper->redirector('show');
    }

}

